//
//  CheckPayPasswordViewController.m
//  HuLaQuan
//
//  Created by hok on 1/21/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "CheckPayPasswordViewController.h"

#import "VerifyPayPasswordEngine.h"

@interface CheckPayPasswordViewController ()

@property (nonatomic,strong) VerifyPayPasswordEngine *verifyPayPasswordEngine;

@end

@implementation CheckPayPasswordViewController

- (VerifyPayPasswordEngine *)verifyPayPasswordEngine
{
    if (!_verifyPayPasswordEngine) {
        _verifyPayPasswordEngine = [[VerifyPayPasswordEngine alloc] init];
    }
    return _verifyPayPasswordEngine;
}
- (void)initData
{
    self.type = PayPassword;
    self.titleOfNav = @"验证支付密码";
    self.titleOfPassword = kCheckPayPasswordHint;
}

-(NSString *)finish:(NSString *)pwd{
    [self.passwordAndInfos setObject:pwd forKey:@"checkpassword"];
    
    [YuNetworkStatusUtilities showProgressMessage:NETWORK_LOADING];
    [self.verifyPayPasswordEngine verifyPayPassword:pwd];
    return pwd;
}

#pragma mark - Call Back
- (void)verifyPayPasswordFinish:(NSNotification*) notification
{
    
    [YuNetworkStatusUtilities dismissHUD];
    NSDictionary *messageDic = [notification object];//获取到传递的对象
    if ([messageDic[@"isSuccess"] boolValue]) {
        
        [self confirmPayPasswordFinish];
    }else{
        [self showNetWorkError:messageDic[@"message"]];
        
    }
    
}
/**
 *  验证支付密码通过后调用，子类需要overwrite此function
 */
- (void)confirmPayPasswordFinish
{
    
}
#pragma mark - Controller Life Cycle
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(verifyPayPasswordFinish:) name:@"VerifyPayPasswordFinish" object:nil];
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"VerifyPayPasswordFinish" object:nil];
    [super viewWillDisappear:YES];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
